package com.dmatek.uwb.xml.util.iparse.bean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.dom4j.Element;
import com.dmatek.uwb.xml.util.iparse.IDomParse;
import com.dmatek.uwb.xml.util.iparse.IMapParse;
/***
 * map配置解析抽象接口
 * @author zhangfu
 * @data 2019年6月22日 下午3:19:38
 * @Description
 */
public abstract class BaseMapParse<V, T extends Map<String, V>> implements IMapParse<V, T> {
	private IDomParse<?> iDomParse;
	public BaseMapParse(IDomParse<?> iDomParse) {
		super();
		this.iDomParse = iDomParse;
	}
	public IDomParse<?> getiDomParse() {
		return iDomParse;
	}
	public void setiDomParse(IDomParse<?> iDomParse) {
		this.iDomParse = iDomParse;
	}
	@SuppressWarnings({ "unchecked"})
	@Override
	public T parse(Element element, Map<String, Object> superMap) throws Exception {
		HashMap<String, V> map = new HashMap<String, V>();
		List<Element> elements = element.elements("bean");
		for (Element ele : elements) {
			// 获取Id
			String key = ele.attributeValue("id");
			Object value = getiDomParse().parse(ele, superMap);
			map.put(key, (V) value);
		}
		return (T) map;
	}
}
